<?php

class ImportacionPosgrado extends CI_Controller {

    function __construct() {
        parent :: __construct();
        $this->load->helper('comunes');
        $this->load->helper('Form');
        checkvaliduser();
    }

    function index() {
        $datos['header'] = $this->load->view('importacion/importar_index_posgrado', array('error' => ''), true);
        $this->load->view('template', $datos);
    }

    function do_generales() {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'txt';
        $config['max_size'] = '1000';
        $this->load->library('upload', $config);
        if (!$this->upload->do_upload()) {
            $error = array('error' => $this->upload->display_errors());
            $data['header'] = $this->load->view('importacion/importar_index_posgrado_posgrado', $error, true);
            $this->load->view('template', $data);
        } else {
            $this->load->model('importacion_model');
            $data = $this->importacion_model->importar_generales();
            $data['header'] = $this->load->view('importacion/importar_success_posgrado', $data, true);
            $this->load->view('template', $data);
        }
        $data = $this->upload->data();
        $tempFile = $data['full_path'];
        @unlink($tempFile);
    }
    
    function do_egresados() {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'txt';
        $config['max_size'] = '1000';
        $this->load->library('upload', $config);
        if (!$this->upload->do_upload()) {
            $error = array('error' => $this->upload->display_errors());
            $data['header'] = $this->load->view('importacion/importar_index_posgrado_posgrado', $error, true);
            $this->load->view('template', $data);
        } else {
            $this->load->model('importacion_model');
            $data = $this->importacion_model->importar_egresados();
            $data['header'] = $this->load->view('importacion/importar_success_posgrado', $data, true);
            $this->load->view('template', $data);
        }
        $data = $this->upload->data();
        $tempFile = $data['full_path'];
        @unlink($tempFile);
    }
    
    function do_ingreso() {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'txt';
        $config['max_size'] = '1000';
        $this->load->library('upload', $config);
        if (!$this->upload->do_upload()) {
            $error = array('error' => $this->upload->display_errors());
            $data['header'] = $this->load->view('importacion/importar_index_posgrado', $error, true);
            $this->load->view('template', $data);
        } else {
            $this->load->model('importacion_model');
            $data = $this->importacion_model->importar_ingreso();
            $data['header'] = $this->load->view('importacion/importar_success_posgrado', $data, true);
            $this->load->view('template', $data);
        }
        $data = $this->upload->data();
        $tempFile = $data['full_path'];
        @unlink($tempFile);
    }
    
    function do_permanencia() {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'txt';
        $config['max_size'] = '1000';
        $this->load->library('upload', $config);
        if (!$this->upload->do_upload()) {
            $error = array('error' => $this->upload->display_errors());
            $data['header'] = $this->load->view('importacion/importar_index_posgrado', $error, true);
            $this->load->view('template', $data);
        } else {
            $this->load->model('importacion_model');
            $data = $this->importacion_model->importar_permanencia();
            $data['header'] = $this->load->view('importacion/importar_success_posgrado', $data, true);
            $this->load->view('template', $data);
        }
        $data = $this->upload->data();
        $tempFile = $data['full_path'];
        @unlink($tempFile);
    }
    
    function do_titulados() {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'txt';
        $config['max_size'] = '1000';
        $this->load->library('upload', $config);
        if (!$this->upload->do_upload()) {
            $error = array('error' => $this->upload->display_errors());
            $data['header'] = $this->load->view('importacion/importar_index_posgrado', $error, true);
            $this->load->view('template', $data);
        } else {
            $this->load->model('importacion_model');
            $data = $this->importacion_model->importar_titulados();
            $data['header'] = $this->load->view('importacion/importar_success_posgrado', $data, true);
            $this->load->view('template', $data);
        }
        $data = $this->upload->data();
        $tempFile = $data['full_path'];
        @unlink($tempFile);
    }

}
